package com.zzg.elasticjob.job;

import javax.annotation.Resource;

import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.AbstractDistributeOnceElasticJobListener;
import com.zzg.dao.JobTaskDao;
import com.zzg.entity.JobTask;

public class ElasticJobListener extends AbstractDistributeOnceElasticJobListener{
	@Resource
	private JobTaskDao taskDao;
	
	public ElasticJobListener(long startedTimeoutMilliseconds, long completedTimeoutMilliseconds) {
		super(startedTimeoutMilliseconds, completedTimeoutMilliseconds);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void doAfterJobExecutedAtLastCompleted(ShardingContexts arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doBeforeJobExecutedAtLastStarted(ShardingContexts shardingContexts) {
		// TODO Auto-generated method stub
		//任务执行完成后更新状态为已执行
        JobTask jobTask = taskDao.findOne(Long.valueOf(shardingContexts.getJobParameter()));
        jobTask.setStatus(1);
        taskDao.update(jobTask);
	}
	
}
